/** v2.8.2 LiuYuXuan
 * label: 一级菜单栏的名称
 *  children: [ 二级菜单栏的配置
 *     label: 二级菜单栏的名称
 *     name: 二级菜单栏的路由name值,
 *     childrenName: 二级菜单栏页面中对应的内页，子页面
 *  ]
 */
import { constantRouterMap } from '@/router/index.js';
/**
 * sidebarData 已经在 v3.3.4 弃用
 * 改用通过 getSideBarData 方法，根据路由文件动态生成
 * time：20230215
 */
export const sidebarData = [
  {
    label: '首页',
    children: [
      {
        label: '统计报表',
        name: 'total',
        childrenName: ['totalTabelData', 'createBaseReport', 'editBaseReport', 'createCollectReport', 'editCollectReport']
      }
    ]
  },
  {
    label: '审批',
    children: [
      {
        label: '待办中心',
        name: 'todo',
        childrenName: ['todoDetail']
      },
      {
        label: '审批模块',
        name: 'approvalModule'
      }
    ]
  },
  {
    label: '订单',
    children: [
      {
        label: '渠道订单',
        name: 'allOrder',
        childrenName: ['createOrder', 'batchcreate', 'orderupload', 'editOrder', 'orderDetail']
      },
      {
        label: '项目订单',
        name: 'projectList',
        childrenName: ['projectChild', 'projectDetail', 'projectOrderCreate', 'projectOrderEdit', 'createProject', 'editProject', 'projectChildDetail', 'createProjectChild', 'editProjectChild']
      },
      {
        label: '有赞订单',
        name: 'commerceOrder',
        childrenName: ['commerceOrderFresh']
      },
      {
        label: '萌力订单',
        name: 'mengliOrder',
        childrenName: ['mengliOrderAdd', 'mengliOrderEdit', 'mengliOrderDetail']
      }
    ]
  },
  {
    label: '资源',
    children: [
      {
        label: '账号资源',
        name: 'resource',
        childrenName: ['createResource', 'editResource', 'resourceupload']
      },
      {
        label: '预约日历',
        name: 'subcribe'
      },
      {
        label: '询单',
        name: 'ConsultOrder',
        childrenName: ['ConsultOrderDetail', 'createOrderBatch']
      },
      {
        label: '有赞商品',
        name: 'commerceManage',
        childrenName: ['commerceLog']
      },
      {
        label: '萌力库存',
        name: 'mengliInventory',
        childrenName: ['mengliInventoryLog', 'mengliInventoryCreate', 'mengliInventoryDetail', 'mengliInventoryEdit']
      },
      {
        label: '表情包',
        name: 'mengliPlanet',
        childrenName: ['mengliCreate', 'mengliIpEdit', 'mengliDetail', 'mengliEdit']
      },
      {
        label: 'IP形象',
        name: 'mengliIpImage',
        childrenName: ['mengliIpImageCreate', 'mengliIpImageEdit']
      }
    ]
  },
  {
    label: '运营',
    children: [
      {
        label: '精力分配',
        name: 'energy',
        childrenName: ['energyCreate', 'energyEdit', 'energyDetail', 'energyDetail', 'energyDetailEdit']
      }, {
        label: '目标管理',
        name: 'target'
      }, {
        label: '发布管理',
        name: 'publish'
      }, {
        label: '账号监测',
        name: 'accounts',
        childrenName: ['accountsDetail']
      }
      // {
      //   label: '实时热榜',
      //   name: 'hotList'
      // }
    ]
  },
  {
    label: '客户',
    children: [
      {
        label: '销售客户',
        name: 'customer',
        childrenName: ['detailCustomer', 'settleCustomer', 'createCustomer', 'editCustomer']
      },
      {
        label: '萌力客户',
        name: 'mengliCustomer',
        childrenName: ['editMengliCustomer', 'createMengliCustomer']
      },
      {
        label: '客户结算',
        name: 'customersettle'
      },
      {
        label: '回款报表',
        name: 'returnedMoney',
        children: ['paymentReceived']
      }
    ]
  },
  {
    label: '供应',
    children: [
      {
        label: '飞博供应商',
        name: 'supplierManage',
        childrenName: ['supplierDetail', 'supplierCreate', 'supplierManageDetail']
      },
      {
        label: '有赞供应商',
        name: 'commerceSupplier',
        childrenName: ['commerceSupplierCreate', 'commerceSupplierEdit', 'commerceSupplierDetail']
      },
      {
        label: '萌力供应商',
        name: 'mengliSuppliers',
        childrenName: ['mengliCreateSupplier', 'mengliEditSupplier']
      },
      {
        label: '签约内审',
        name: 'signUp',
        childrenName: ['signUpDetail', 'signUpCreate', 'signUpEdit']
      },
      {
        label: '飞来用户',
        name: 'flyUser',
        childrenName: ['flyUserDetail']
      },
      {
        label: '飞来询单',
        name: 'flyNotice',
        childrenName: ['flyNoticeDetail', 'flyNoticeEdit', 'flyNoticeCreate']
      },
      {
        label: '飞来询价',
        name: 'flyPrice',
        childrenName: ['flyPriceDetail', 'flyPriceEdit', 'flyPriceCreate']
      }
    ]
  },
  {
    label: '财务',
    children: [
      {
        label: '财务流水',
        name: 'dayAccount',
        childrenName: ['createDayAccount', 'editDayAccount', 'chargeOff', 'chargeOffDetail']
      }, {
        label: '财务封账',
        name: 'sealingAccount',
        childrenName: ['sealingStepsDetail', 'sealingAccountDetail']
      }, {
        label: '成本管理',
        name: 'costManageList',
        childrenName: ['costDetail']
      }, {
        label: '开票申请',
        name: 'issueInvoice',
        childrenName: ['createIssueInvoice', 'issueInvoiceEdit', 'issueInvoiceDetail']
      }, {
        label: '发票作废',
        name: 'invoiceAbandon',
        childrenName: ['createInvoiceAbandon', 'editInvoiceAbandon', 'invoiceAbandonDetail']
      }, {
        label: '销项发票',
        name: 'invoice',
        childrenName: ['createInvoice', 'editInvoice', 'invoiceDetail']
      }, {
        label: '进项发票',
        name: 'inputInvoice',
        childrenName: ['inputInvoiceDetail', 'inputInvoiceEdit']
      }, {
        label: '付款申请',
        name: 'supplier',
        childrenName: ['supplierCreate', 'supplierDetail']
      }, {
        label: '员工报销',
        name: 'reimbursement',
        childrenName: ['createReimbursement', 'reimbursementEdit', 'reimbursementDetail']
      }, {
        label: '借款申请',
        name: 'loan',
        childrenName: ['createLoan', 'loanEdit', 'loanDetail']
      }, {
        label: '还款申请',
        name: 'payBack',
        childrenName: ['payBackDetail', 'payBackCreate', 'payBackEdit']
      }, {
        label: '转交欠款',
        name: 'arrearsTransfer',
        childrenName: ['arrearsTransferDetail', 'arrearsTransferCreate', 'arrearsTransferEdit']
      }
    ]
  },
  {
    label: '法务',
    children: [
      {
        label: '合同审批',
        name: 'ContractManagement',
        childrenName: ['CreateContract', 'EditContract', 'contractDetail']
      },
      {
        label: '合同管理',
        name: 'ContractManagementHistory'
      },
      {
        label: '申请原件',
        name: 'original',
        children: ['originalCreate', 'originalEdit', 'originalDetail']
      }
    ]
  },
  {
    label: '设置',
    children: [
      {
        label: '权限设置',
        name: 'userAuthManage',
        childrenName: ['createRole', 'authEditRole', 'createOperator', 'editOperator']
      },
      {
        label: '用户设置',
        name: 'user',
        childrenName: ['createUser', 'fileupload']
      },
      {
        label: '流程设置',
        name: 'ContractProcess',
        childrenName: ['ContractProcessEdit', 'ContractProcessCreate']
      },
      {
        label: '通用设置',
        name: 'systemSetting'
      },
      {
        label: '交接管理',
        name: 'userHandover',
        childrenName: ['addHandover']
      },
      {
        label: '操作日志',
        name: 'operatorLogManage'
      },
      {
        label: '部门管理',
        name: 'departmentManage'
      },
      {
        label: 'BP管理',
        name: 'BPManage'
      }
    ]
  }
];
/**
 * 根据路由文件来生成帮助中心侧边栏
 * 结构
  {
    label: 标题
    children: [
      {
        label: 标题
        name: 路由name
        childrenName: 内页列表
      }
    ]
  }
 */
export const getSideBarData = () => {
  const routerList = _.cloneDeep(constantRouterMap);
  const list = [];
  routerList.forEach(parentItem => {
    if (!parentItem.hidden) {
      const levelOne = {
        label: parentItem.meta.title,
        children: [],
        name: parentItem.name
      };
      if (parentItem.children) {
        const hidePage = []; // 内页列表
        // 填充列表页
        parentItem.children.forEach(twoItem => {
          const twoPath = `${parentItem.path}${twoItem.path.indexOf('/') < 0 ? '/' : ''}${twoItem.path}`;
          // 如果有三级路由
          if (twoItem.children && twoItem.children.length) {
            twoItem.children.forEach(threeItem => {
              if (!threeItem.hidden) {
                const threePath = `${twoPath}${threeItem.path.indexOf('/') < 0 ? '/' : ''}${threeItem.path}`;
                levelOne.children.push({
                  label: threeItem.meta.title,
                  name: threeItem.name,
                  path: threePath,
                  childrenName: []
                });
              } else {
                hidePage.push(threeItem);
              }
            });
          } else {
            // 只有二级路由
            if (!twoItem.hidden) {
              levelOne.children.push({
                label: twoItem.meta.title,
                name: twoItem.name,
                path: twoPath,
                childrenName: []
              });
            } else {
              hidePage.push(twoItem);
            }
          }
        });
        // 将内页填充进列表页的childrenName
        hidePage.forEach(item => {
          if (item.hidden && item.meta && item.meta.activeMenu) {
            const curParent = levelOne.children.find(i => i.path === item.meta.activeMenu);
            if (curParent) {
              curParent.childrenName.push(item.name);
            }
          }
        });
      }
      list.push(levelOne);
    }
  });
  return list;
};
